﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="qst_manage_detail.aspx.cs" Inherits="Ccit.OA.Question.qst_manage_detail" %>
<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>问卷管理-问题设置</title>
    <script language="javascript" type="text/javascript" src="../script/jquery.js"></script>
    <script language="javascript" type="text/javascript" src="../script/StringClass_Ext.js"></script>
    <script language="javascript" type="text/javascript" src="../script/jsonlib.js"></script>
    <script language="javascript" src="../script/jwindow.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jcontrol.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jbase64.js" type="text/javascript"></script>
    <script type="text/javascript">
        function CheckFrom()
        {
            var number = $get("txtNumber").value;
             if(number.Trim()!="0")
            {
                if(!number.IsNumber())
                {
                    alert("选项数必须为数字!"); 
                    return false;
                }
            }
            var order = $get("txtOrder").value;
            if(order.Trim()!="")
            {
                if(!order.IsNumber())
                {
                    alert("顺序号必须为数字!"); 
                    return false;
                }
            }
            return true;
        }
        function doSave(oType)
        {
            if(CheckFrom() ==false) return false;
            var msQuentions = {};
            msQuentions.id=$get("_hidRecid").value
            msQuentions.qid=$get("_hidQuenID").value
            msQuentions.describe = $get("txtDescribe").value;
            var rbtn = new RadioList("radioType");
               msQuentions.type = rbtn.checkedValue;
            var opinions = document.getElementById("chkOpinion");
            if(opinions.checked==true)
            {
                msQuentions.opinions="1";
            }
            else
            {
                msQuentions.opinions="0";
            }
            msQuentions.number = $get("txtNumber").value;
            msQuentions.sorder = ($get("txtOrder").value!="")?$get("txtOrder").value:"0";
            msQuentions.Options = GetDetails();
            var jsonExpr = JSON.stringify(msQuentions,function(key,value){return value;}); 
            msQuentions = null;
            PageMethods.DoSave(jsonExpr,oType,ClientBack);
        }
        function ClientBack(vResult)
        {
           eval("resultObj ="+vResult)
                if(resultObj.result!="-999")
                {
                    alert(resultObj.message);
                    switch(resultObj.ctrtype){
                         case "1":
                            $get("_hidRecid").value = resultObj.result;
                            break;
                         case "2":
                            doClear();
                            break;
                         case "3":
                            doBack();
                            break;
                         case "4":                            
                            break;
                    }
                }
                else
                {
                    alert(resultObj.message)
                }
                resultObj = null;
        }
        function GetDetails()
        {
            var otable=document.getElementById("tbProduct");
            var orowcount=otable.rows.length;
            var orow; 
            var DetailArray=new Array();
            for(var i=0;i<orowcount;i++)
            {
                orow=otable.rows[i]; 
                var order=orow.cells(0).innerText;
                var optionsname=orow.cells(1).children(0).value;
                var msOptions={}; 
                msOptions.order=order;
                msOptions.optionsname=optionsname;                         
                DetailArray.push(msOptions);
            }
            return DetailArray;
        }
         function doClear()
          {
                $get("_hidRecid").value = "";
                $get("txtDescribe").value="";
                $get("txtNumber").value="";
                $get("txtOrder").value="";
                doRemoveAllRow("tbProduct"); 
          }
         function doBack()
          { 
               var sRecid = $get("_hidQuenID").value;
//               var oPageParam="Id="+sRecid;
//               var oEncodeParam=base64encode(oPageParam);
//               var strURL = "qst_manage_edit.aspx?"+oPageParam;
//               window.opener.location.href = strURL;
//                 window.opener.document.getElementById('_hidsRecid').value= sRecid;
                //window.opener.location.reload(); 
                 opener.document.getElementById("_hidsRecid").value=sRecid;
                 opener.DoBack();
                 window.close();
          }
          function doRemoveAllRow(vTableName)  
            { 
                var otable = document.getElementById(vTableName);              
                var orowcount=otable.rows.length;    	        
                for(var i=0;i<orowcount;i++)
                {
                    var orow=otable.rows[0];
	                otable.deleteRow(orow.id);
	            }
            }
             //删除行
        function doRemoveRows(vTableName,vsRecid,vRowId)  
        {             
            var oType="4";
            var otable = document.getElementById(vTableName);
		    var oRowIndex = document.getElementById(vRowId).rowIndex;		        	        
		    if (confirm("删除当前行,是否继续?"))
		        PageMethods.DoOperate(vsRecid,oType,ClientBack); 
		        otable.deleteRow(oRowIndex);
        }
    </script>
</head>
<body>
    <ccit:ActionForm id="form1" runat="server">
         <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        </asp:ScriptManager> 
        <!---->
	    <input type="hidden" id="_hidQuenID" runat="server" />
	    <!---->
	    <input type="hidden" id="_hidRecid" runat="server" />
        
       <table class="tbToolbar" cellpadding="0" cellspacing="0" width="98%" align="center">
            <tr>
            <td width="2%" align="left">
                <div class="tbSeparator">
                </div>
            </td>
             <td class="titlebar" width="38%">                   
                 问卷管理-编辑问卷信息
            </td>
            <td align="right">               				 
					<nobr></nobr>            
            </td>
            <td align="right">
                <nobr>
            </td>            
          </tr>
         </table> 
        <table cellpadding="0" class="tableborder" cellspacing="0" width="98%" align="center" id="tdMessage" runat="server">
            <tr>
			  <td  width="15%" height="14" align="right" class="pformleft"><nobr>问卷标题</nobr>			  </td>
				<td colspan="3" align="left" class="pformright">
				    <asp:Label  ID="txtTitle" Runat="server" Width="98%" 
                         >&nbsp;</asp:Label>			  				    </td>
			</tr>
			<tr> 
				<td width="15%" height="14" align="right" class="pformleft"><nobr>问题描述</nobr>				</td>
				<td colspan="3" align="left" class="pformright">
				<asp:TextBox  ID="txtDescribe" Runat="server" CssClass="input"   
                        Width="98%"></asp:TextBox>			  				    </td>
		    </tr>
			
			<tr>
				<td class="pformleft" align="right"><nobr>选项类型</nobr></td>
				<td width="35%" align="left" class="pformrightline" valign="top">				    
                    <asp:RadioButtonList ID="radioType" runat="server" Height="16px" 
                        RepeatDirection="Horizontal" Width="158px">
                        <asp:ListItem Value="0" Selected>单选</asp:ListItem>
                        <asp:ListItem Value="1">多选</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
				<td class="pformright" align="center" width="11%" colspan="2">
                    <asp:CheckBox ID="chkOpinion" runat="server" Text="答卷人可以输入其他意见" />
				</td>			 
			</tr> 
			<tr>
				<td class="pformleft" align="right"><nobr>每行选项数</nobr>			  </td>
				<td width="40%" align="left" class="pformrightline" valign="top">	
				<nobr>			    
                   <asp:TextBox  ID="txtNumber" Runat="server" CssClass="input"   
                        Width="20%" Text="0" ></asp:TextBox>		
                        <font color="red">(0表示所有选项在一行内显示)</font>
                </nobr>	  	
                </td>
				<td class="pformleft" align="center" width="11%">显示顺序</td>
				<td class="pformright" align="left" width="39%">
				    <asp:TextBox  ID="txtOrder" Runat="server" CssClass="input" Width="60%"></asp:TextBox>  
				</td>
			</tr> 
         </table>
         <table id="Table1" runat="server" cellpadding="0" cellspacing="0" width="98%" align="center" >
            <tr>
                <td colspan="2">
                </td>
           </tr>
            <tr>
                <td align="left" width="70%">
                  >>>选项列表
                           </td>  
                <td align="right">
                <nobr>　
                     <a  id="lnbAdd" Runat="server" class="linktext"  
                                href="javascript:doAdd()">
							        <img src="../images/toolbar/new.gif" border="0">
				    </a>
			　　</nobr>            
            </td>               
            </tr>            
         </table>
         <table runat="server" cellpadding="0" cellspacing="0" width="98%" align="center" >
            <tr id="irow_0"  class="listtitle"> 
                <td width="8%" align="center" class="listcelltitle">序号</td>
                <td width="30%" align="center" class="listcelltitle">选项名称</td> 
                <td width="10%" align="center" class="listcelltitle">操作</td>
           </tr> 
         </table>
         <table id="tbProduct"  width="98%" height="20" align="center" cellpadding="0" cellspacing="0"     runat="server">
         </table>
      <table  width="98%" height="20" align="center" cellpadding="0" cellspacing="0"     runat="server">
         <tr  class="pformstrip" height="20">
           <td colspan="4" align="center">
                <input type="button" id="btnSave" value="保存" class="button" onclick="doSave('1')" />
                &nbsp;
                <input type="button" id="btnSaveCont" value="保存并新增" class="button" onclick="doSave('2')" />
                &nbsp;
                <input type="button" id="btnSaveBack" value="保存并关闭" class="button" onclick="doSave('3')" />
                &nbsp;  
                <input type="button" id="btnBack" value="关闭" class="button" onclick="doBack()" />
                &nbsp;
            </td>
        </tr>
    </table> 
    </ccit:ActionForm>
   <script type="text/javascript">
        function doAdd()
       {
            var oRowNode;
		    var otable = document.getElementById("tbProduct");
		    var rowLen;
		    var orow;
		    var ocell;	
		    var otxt;
		    var oimg;
		        
		       /* 计算行Id最大序号 */
			var maxIndex = 1;
			var iIndex = 0;
			if(otable.rows.length >= 1)
			{
				orow = otable.rows[otable.rows.length - 1];
				iIndex = orow.id.indexOf("_");
				if(iIndex != -1)
				{
					maxIndex = parseInt(orow.id.substring(iIndex + 1)) + 1;
				}
			}
  		        rowLen = otable.rows.length;				
			    orow = otable.insertRow();
			    orow.className="listrow2";
			    orow.id = "row_" + (maxIndex);
			    
		        //序号
			    ocell = orow.insertCell(); 
			    ocell.align = "center";
			    ocell.width="8%";
			    ocell.className = "listcellrow";
			    otxt=document.createElement("<span>");
			    otxt.innerText = maxIndex;
			    ocell.appendChild(otxt); 

                //名称
                ocell = orow.insertCell(); 
                ocell.align = "center";
                ocell.width="30%";
                ocell.className = "listcellrow";
                otxt = document.createElement("<input id='txtName_"+ maxIndex +"' type='text' class='input' style='WIDTH:99%'>");
                ocell.appendChild(otxt);
                  

     
			    //操作		
			    ocell = orow.insertCell();
			    ocell.align = "center";
			    ocell.className = "listcellrow";
			     ocell.width="10%";
			    oanchor = document.createElement("<a href=\"javascript:doRemoveRow('tbProduct','" + orow.id + "')\">");						
//			    oimg = document.createElement("<img src='../images/toolbar/16X16/delete.gif' border='0' />");
    			var ospanDelete=document.createElement("<span>");
			    ospanDelete.innerText="删除"; 
			    //oanchor.appendChild(oimg);
			    oanchor.appendChild(ospanDelete);
			    ocell.appendChild(oanchor);		 
        }
        
	    //删除行
        function doRemoveRow(vTableName,vRowId)  
        {             
            var otable = document.getElementById(vTableName);
		    var oRowIndex = document.getElementById(vRowId).rowIndex;		        	        
		    if (confirm("删除当前行,是否继续?"))
		        otable.deleteRow(oRowIndex);
        }
   </script>
</body>
</html>
